<template>
  <!-- 跳转 -->
  <div>
    <el-button type="primary" @click="skip">跳转</el-button>
  </div>
</template>

<script setup>
import { onMounted, watch } from "vue";
import { useRouter, useRoute } from "vue-router";
const router = useRouter();
let skip = () => {
  router.push({
    name: "购物车",
    params: {
      draftNo: 1,
    },
  });
};
const route = useRoute();
console.log(route.name);

// 使用 watch 监听 route.name 的变化
watch(
  () => route.name,
  (to, from) => {
    console.log("路由名称从", from, "变化到", to);
  }
);
onMounted(() => {
  console.log(1);
});
</script>

<style lang="scss" scoped></style>
